package cn.globalph.housekeeper.ui.login.code

import android.util.Log
import cn.globalph.housekeeper.data.model.BaseModel
import cn.globalph.housekeeper.data.model.LoginModel
import cn.globalph.housekeeper.data.params.CodeParam
import cn.globalph.housekeeper.data.params.LoginCodeParam
import cn.globalph.housekeeper.data.retrofit.HttpConstant
import cn.globalph.housekeeper.data.retrofit.HttpManager

class LoginWithCodeRepository (
    private val httpManager: HttpManager
){
    suspend fun getCode(phone:String):BaseModel<String>{
        val validation = httpManager.api.checkPhoneValidation(phone)
        return if(validation.isSuccessful()){
            if(validation.data!!){
                httpManager.api.sendCode(CodeParam(phone))
            }else{
                val fakeModel:String? = null
                BaseModel(400,"手机号码未注册",fakeModel)
            }
        }else{
            val fakeModel:String? = null
            BaseModel(validation.code,validation.message,fakeModel)
        }
    }

    suspend fun loginByCode(phone: String,code:String):BaseModel<LoginModel>{
        return httpManager.api.loginByCode(LoginCodeParam(phone,code))
    }
}